import sun.audio.AudioPlayer;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class RoleSelection extends JPanel {
    RoleSelection(final JFrame jFrame, final JPanel launchPage){
        this.setLayout(null);
        final JPanel roleSelection = this;

        JLabel back = new JLabel();
        back.setIcon(new ImageIcon(Images.back));
        back.setBounds(50,30,50,50);
        this.add(back);

        final JLabel xiyangyang_introduction = new JLabel();
        xiyangyang_introduction.setIcon(new ImageIcon(Images.xiyangyang_portrait));
        xiyangyang_introduction.setBounds(80,120,267,422);
        this.add(xiyangyang_introduction);

        final JLabel meiyangyang_introduction = new JLabel();
        meiyangyang_introduction.setIcon(new ImageIcon(Images.meiyangyang_portrait));
        meiyangyang_introduction.setBounds(360,120,267,422);
        this.add(meiyangyang_introduction);

        final JLabel langyangyang_introduction = new JLabel();
        langyangyang_introduction.setIcon(new ImageIcon(Images.langyangyang_portrait));
        langyangyang_introduction.setBounds(640,120,267,422);
        this.add(langyangyang_introduction);

        JLabel Launchpage_background = new JLabel();
        Launchpage_background.setIcon(new ImageIcon(Images.roleSelection_background));
        Launchpage_background.setBounds(0,-20,1000,666);
        this.add(Launchpage_background);

        xiyangyang_introduction.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                roleSelection.setVisible(false);
                AudioPlayer.player.stop(MyMusic.zhutiqu);
                PlayGame playGame = new PlayGame(jFrame,new Xiyangyang());
                jFrame.add(playGame);
                playGame.action();
                playGame.requestFocus();//设为焦点
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                xiyangyang_introduction.setIcon(new ImageIcon(Images.xiyangyang_introduction));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                xiyangyang_introduction.setIcon(new ImageIcon(Images.xiyangyang_portrait));
            }
        });

        meiyangyang_introduction.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                super.mouseClicked(e);
                roleSelection.setVisible(false);

                PlayGame playGame = new PlayGame(jFrame,new Meiyangyang());
                jFrame.add(playGame);
                playGame.action();
                playGame.requestFocus();//设为焦点
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                meiyangyang_introduction.setIcon(new ImageIcon(Images.meiyangyang_introduction));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                meiyangyang_introduction.setIcon(new ImageIcon(Images.meiyangyang_portrait));
            }
        });

        langyangyang_introduction.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                super.mouseClicked(e);
                roleSelection.setVisible(false);

                PlayGame playGame = new PlayGame(jFrame,new Langyangyang());
                jFrame.add(playGame);
                playGame.action();
                playGame.requestFocus();//设为焦点
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                langyangyang_introduction.setIcon(new ImageIcon(Images.langyangyang_introduction));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                langyangyang_introduction.setIcon(new ImageIcon(Images.langyangyang_portrait));
            }
        });

        back.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                roleSelection.setVisible(false);
                launchPage.setVisible(true);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
            }
        });

    }
    public static void main(String[] args) {
//        JFrame jFrame = new JFrame();
//        RoleSelection playGame = new RoleSelection(jFrame);
//        jFrame.add(playGame);
//        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        jFrame.setSize(1000, 666);
//        jFrame.setLocationRelativeTo(null);
//        jFrame.setVisible(true);
    }
}
